package com.qf.comfig;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;
@Aspect
@Component
public class aopConfig {
    @Pointcut("execution(* com.qf.service.impl.*.*(..))")
    public void pc(){}

//    @Before("pc()")
//    public void before(){
//        System.out.println("前置");
//    }
//
//    @After("pc()")
//    public void after(){
//        System.out.println("后置");
//    }
//
//    @AfterThrowing("pc()")
//    public void myThrows(){
//        System.out.println("异常");
//    }

    @Around("pc()")
    public Object Around(ProceedingJoinPoint proceedingJoinPoint){
        try {
            System.out.println("前置");
            Object proceed = proceedingJoinPoint.proceed();
            System.out.println("后置");
            return proceed;
        } catch (Throwable throwable) {
            System.out.println("异常增强");
            throw new RuntimeException("捕获异常");
        } finally {
            System.out.println("最终");
        }
    }
}
